package com.peza.bikelog.common.domain.polar;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.WordUtils;

import com.peza.bikelog.common.util.Util;

public class HrmParams implements Writable{

	private static Util util = Util.getInstance();
	
	private String version;
	private String monitor;
	private SMode sMode;
	private String date;
	private String startTime;
	private String length;
	private String interval;
	private int upper1;
	private int lower1;
	private int	upper2;
	private int lower2;
	private int	upper3;
	private int lower3;
	private String timer1; //00:00:00.0
	private String timer2; //00:00:00.0
	private String timer3; //00:00:00.0
	private int activeLimit; //0
	private int maxHR;		//181
	private int restHR;		//55
	private int startDelay;	//0
	private int VO2max;		//60
	private int weight;		//85
	
	
	public HrmParams(){
		
	}
	
	public HrmParams(String data){
		
		String [] fields = data.split("\n");
		Map<String,String> params = new HashMap<String,String>();
		
		for (String field : fields){
			String [] tokens = field.split("=");
			String key = tokens[0];
			String value = tokens[1];
			params.put(key, value);
		}
		
		
		version = params.get("Version");
		monitor = params.get("Monitor");
		sMode = new SMode(params.get("SMode"));
		date = params.get("Date");
		startTime = params.get("StartTime");
		length = params.get("Length");
		interval = params.get("Interval");
		upper1 = util.convertToInt(params.get("Upper1"));
		lower1 = util.convertToInt(params.get("Lower1"));
		upper2 = util.convertToInt(params.get("Upper2"));
		lower2 = util.convertToInt(params.get("Lower2"));
		upper3 = util.convertToInt(params.get("Upper3"));
		lower3 = util.convertToInt(params.get("Lower3"));
		timer1 = params.get("Timer1"); //00:00:00.0
		timer2 = params.get("Timer2"); //00:00:00.0
		timer3 = params.get("Timer3"); //00:00:00.0
		activeLimit = util.convertToInt(params.get("ActiveLimit")); //0
		maxHR = util.convertToInt(params.get("MaxHR"));		//181
		restHR = util.convertToInt(params.get("RestHR"));		//55
		startDelay = util.convertToInt(params.get("StartDelay"));	//0
		VO2max = util.convertToInt(params.get("VO2max"));		//60
		weight = util.convertToInt(params.get("Weight"));		//85
				
		
	}

	
	
	
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getMonitor() {
		return monitor;
	}
	public void setMonitor(String monitor) {
		this.monitor = monitor;
	}
	public SMode getsMode() {
		return sMode;
	}
	public void setsMode(SMode sMode) {
		this.sMode = sMode;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getLength() {
		return length;
	}
	public void setLength(String length) {
		this.length = length;
	}
	public String getInterval() {
		return interval;
	}
	public void setInterval(String interval) {
		this.interval = interval;
	}
	public int getUpper1() {
		return upper1;
	}
	public void setUpper1(int upper1) {
		this.upper1 = upper1;
	}
	public int getLower1() {
		return lower1;
	}
	public void setLower1(int lower1) {
		this.lower1 = lower1;
	}
	public int getUpper2() {
		return upper2;
	}
	public void setUpper2(int upper2) {
		this.upper2 = upper2;
	}
	public int getLower2() {
		return lower2;
	}
	public void setLower2(int lower2) {
		this.lower2 = lower2;
	}
	public int getUpper3() {
		return upper3;
	}
	public void setUpper3(int upper3) {
		this.upper3 = upper3;
	}
	public int getLower3() {
		return lower3;
	}
	public void setLower3(int lower3) {
		this.lower3 = lower3;
	}
	public String getTimer1() {
		return timer1;
	}
	public void setTimer1(String timer1) {
		this.timer1 = timer1;
	}
	public String getTimer2() {
		return timer2;
	}
	public void setTimer2(String timer2) {
		this.timer2 = timer2;
	}
	public String getTimer3() {
		return timer3;
	}
	public void setTimer3(String timer3) {
		this.timer3 = timer3;
	}
	public int getActiveLimit() {
		return activeLimit;
	}
	public void setActiveLimit(int activeLimit) {
		this.activeLimit = activeLimit;
	}
	public int getMaxHR() {
		return maxHR;
	}
	public void setMaxHR(int maxHR) {
		this.maxHR = maxHR;
	}
	public int getRestHR() {
		return restHR;
	}
	public void setRestHR(int restHR) {
		this.restHR = restHR;
	}
	public int getStartDelay() {
		return startDelay;
	}
	public void setStartDelay(int startDelay) {
		this.startDelay = startDelay;
	}
	public int getVO2max() {
		return VO2max;
	}
	public void setVO2max(int vO2max) {
		VO2max = vO2max;
	}
	public int getWeight() {
		return weight;
	}
	public void setWeight(int weight) {
		this.weight = weight;
	}
	

	@Override
	public String toFileString() {
		StringBuffer buffer = new StringBuffer("[Params]\n");
		Class clazz = this.getClass();
		Field[] fields = clazz.getDeclaredFields();
		for (int i = 0; i < fields.length; i++) {
			System.out.println();

			if (fields[i].getModifiers() == 2){
				String fieldName = fields[i].getName();
				fields[i].setAccessible(true);
				Object newObj = null;
				try {
					newObj = fields[i].get(this);
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				buffer.append(WordUtils.capitalize(fieldName) + "=" + newObj + "\n");

			}
			
		}
		buffer.append("\n");
		return buffer.toString();
	}
	
	
}

